/**
 * Copyright 2017 wshunli
 * <p>
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 * <p>
 * http://www.apache.org/licenses/LICENSE-2.0
 * <p>
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */
package com.ptsz.mydatbase.tianditu;

import android.content.Context;

import com.esri.arcgisruntime.arcgisservices.TileInfo;
import com.esri.arcgisruntime.geometry.Envelope;

public class TianDiTuLayerBuilder {
    private int layerType = 0;
    private String cachePath = null;
    private String token = null;
    private String type = null;
    private Context context;

    public TianDiTuLayerBuilder setLayerType(int layerType) {
        this.layerType = layerType;
        return this;
    }

    public TianDiTuLayerBuilder setCachePath(String cachePath) {
        this.cachePath = cachePath;
        return this;
    }

    public TianDiTuLayerBuilder setToken(String token) {
        this.token = token;
        return this;
    }

    public TianDiTuLayerBuilder setType(String type) {
        this.type = type;
        return this;
    }

    public TianDiTuLayerBuilder setContext(Context context) {
        this.context = context;
        return this;
    }

    public TianDiTuLayer build() {
        TianDiTuLayerInfo layerInfo = LayerInfoFactory.getLayerInfo(layerType);
        TileInfo tileInfo = layerInfo.getTileInfo();
        Envelope fullExtent = layerInfo.getFullExtent();
        TianDiTuLayer tianDiTuLayer = new TianDiTuLayer(tileInfo, fullExtent);
        tianDiTuLayer.setLayerType(layerType);
        tianDiTuLayer.setCachePath(cachePath);
        String key = "702c4c7d4cf3870d60aa2205f1a034af";
        if (MapUtils.chinaTdtTK != null) {
            key = MapUtils.chinaTdtTK;
        }

        tianDiTuLayer.setToken(key);//国家
        tianDiTuLayer.setType(type);
        tianDiTuLayer.setContext(context);
        return tianDiTuLayer;
    }
}
